/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * OverzichtenScherm.java
 *
 * Created on 13-jan-2010, 19:33:47
 */
package registratiesysteem;

import java.awt.Color;
import javax.swing.table.DefaultTableModel;
import java.util.ArrayList;

/**
 *
 * @author Martin
 */
class OverzichtenScherm extends javax.swing.JFrame {

    /** Creates new form OverzichtenScherm */
    OverzichtenScherm(BeheerMenu parent) {
        initComponents();
        parentMenu = parent;
        model = (DefaultTableModel) jtOverzicht.getModel();
        jtOverzicht.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
    }

    void initialiseerOverzichtenScherm(UitleningenInvoerScherm uitleningenScherm, BeheerMenu.BewerkFunctie bewerking, ArrayList<ArrayList<String>> resultaten) {
        this.uitleningenScherm = uitleningenScherm;
        String query;
        int size = resultaten.size();

        model.setRowCount(0);
        if (bewerking == BeheerMenu.BewerkFunctie.LID_OVERZICHT) {
            model.setColumnCount(lidKolommen.length);
            model.setColumnIdentifiers(lidKolommen);
            jlTitel.setText("Uitleningen onder lidnummer ");
            query = "select u.fk_lidnr from uitlening u where id = " + resultaten.get(0).get(0);
        } else {
            model.setColumnCount(speelgoedKolommen.length);
            model.setColumnIdentifiers(speelgoedKolommen);
            jlTitel.setText("Uitleningen onder speelgoed code ");
            query = "select u.fk_code from uitlening u where id = " + resultaten.get(0).get(0);
        }
        for (int i = 0; i < size; ++i) {
            model.addRow(resultaten.get(i).toArray());
        }
        resultaten = parentMenu.databaseConnectie.query(query);
        if (resultaten != null) {
            jlTitel.setText(jlTitel.getText() + resultaten.get(0).get(0));
        }
        parentMenu.setStatusbarText(jlStatusbar, "Er zijn " + size + " resultaten gevonden", Color.BLACK);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jlTitel = new javax.swing.JLabel();
        jbOk = new javax.swing.JButton();
        jlStatusbar = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtOverzicht = new javax.swing.JTable() {
            public boolean isCellEditable(int row, int col) {
                return false;
            }
        };

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jlTitel.setFont(new java.awt.Font("Tahoma", 1, 24));
        jlTitel.setText("Overzicht uitleningen per lid");

        jbOk.setText("OK");
        jbOk.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbOkActionPerformed(evt);
            }
        });

        jlStatusbar.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jtOverzicht.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {},
                {},
                {},
                {}
            },
            new String [] {

            }
        ));
        jScrollPane1.setViewportView(jtOverzicht);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jlStatusbar, javax.swing.GroupLayout.DEFAULT_SIZE, 702, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addGap(269, 269, 269)
                .addComponent(jbOk, javax.swing.GroupLayout.PREFERRED_SIZE, 147, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(286, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addGap(41, 41, 41)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 612, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(49, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addGap(155, 155, 155)
                .addComponent(jlTitel)
                .addContainerGap(210, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jlTitel)
                .addGap(35, 35, 35)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 343, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 32, Short.MAX_VALUE)
                .addComponent(jbOk)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jlStatusbar, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jbOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbOkActionPerformed
        setVisible(false);
        uitleningenScherm.setVisible(true);
        //parentMenu.setVisible(true);
}//GEN-LAST:event_jbOkActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton jbOk;
    private javax.swing.JLabel jlStatusbar;
    private javax.swing.JLabel jlTitel;
    private javax.swing.JTable jtOverzicht;
    // End of variables declaration//GEN-END:variables
    // Hier wordt een verwijzing naar het beheermenu opgenomen zodat we
    // vanuit dit scherm terug kunnen keren naar het beheermenu
    private BeheerMenu parentMenu;
    private UitleningenInvoerScherm uitleningenScherm;
    private DefaultTableModel model;
    private String[] lidKolommen = {"ID", "Code", "Uitleendatum", "Verloopdatum", "Inleverdatum", "bijzonderheden"};
    private String[] speelgoedKolommen = {"ID", "Lidnummer", "Uitleendatum", "Verloopdatum", "Inleverdatum", "bijzonderheden"};
   
}
